#region License
// Post.cs
// 
// Copyright (c) 2012 Xoqal.com
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// 
// http://www.apache.org/licenses/LICENSE-2.0
// 
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#endregion

namespace Kaqaz.Models
{
    using System;
    using System.Collections.Generic;
    using System.ComponentModel.DataAnnotations;
    using System.Linq;
    using System.Text;
    using Xoqal.Globalization;
    using Xoqal.Web.Mvc.Globalization;

    public class Post
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="PostViewModel"/> class.
        /// </summary>
        public Post()
        {
            // Set default values
            this.IsCommentsEnable = true;
            this.NeedCommentApprove = true;
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="Post" /> class.
        /// </summary>
        /// <param name="post">The post.</param>
        public Post(Entities.Post post)
        {
            this.Id = post.Id;
            this.Title = post.Title;
            this.Summary = post.Summary;
            this.Content = post.Content;
            this.IsCommentsEnable = post.IsCommentsEnable;
            this.NeedCommentApprove = post.NeedCommentApprove;
            this.CreateTime = post.CreateTime;
            this.LastUpdateTime = post.LastUpdateTime;
            this.TagsString = string.Join("، ", post.Tags.Select(t => t.Name).ToArray());
            this.Tags = post.Tags;
            this.Hits = post.Hits;
        }

        public long Id { get; set; }

        [Required(ErrorMessageResourceName = "RequiredFieldMessage", ErrorMessageResourceType = typeof(Resources.Resource))]
        [DisplayName(typeof(Resources.Resource), "Title")]
        public string Title { get; set; }

        [Required(ErrorMessageResourceName = "RequiredFieldMessage", ErrorMessageResourceType = typeof(Resources.Resource))]
        [DisplayName(typeof(Resources.Resource), "Summary")]
        [UIHint("RichEditor")]
        public string Summary { get; set; }

        [Required(ErrorMessageResourceName = "RequiredFieldMessage", ErrorMessageResourceType = typeof(Resources.Resource))]
        [DisplayName(typeof(Resources.Resource), "Content")]
        [UIHint("RichEditor")]
        public string Content { get; set; }

        [DisplayName(typeof(Resources.Resource), "IsCommentsEnable")]
        public bool IsCommentsEnable { get; set; }

        [DisplayName(typeof(Resources.Resource), "NeedCommentApprove")]
        public bool NeedCommentApprove { get; set; }

        [DisplayName(typeof(Resources.Resource), "CreateTime")]
        public DateTime? CreateTime { get; set; }

        [DisplayName(typeof(Resources.Resource), "LastUpdateTime")]
        public DateTime? LastUpdateTime { get; set; }

        [DisplayName(typeof(Resources.Resource), "Tags")]
        public string TagsString { get; set; }

        [DisplayName(typeof(Resources.Resource), "Hits")]
        public decimal Hits { get; set; }

        public IEnumerable<Entities.Tag> Tags { get; set; }

        public IEnumerable<Entities.Comment> VisibleComments { get; set; }
    }
}
